<?php

namespace app\shop\model\company;

use think\Model;
use think\model\concern\SoftDelete;
/**
 * 应用模型
 */
class Interview extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;

    const RESULT_UN = 0;    //未知
    const RESULT_PASS = 1;  //通过
    const RESULT_FAIL = 2;  //未通过

    public function department()
    {
        return $this->belongsTo('Department', 'department_id', 'id');
    }

    public function station()
    {
        return $this->belongsTo('Station', 'station_id', 'id');
    }

    public function getStatusAttr($value)
    {
        $status = ['未面试', '第一轮', '第二轮', '第三轮'];
        if ($value == 0) {
            return '未面试';
        }
        return $status[$value];
    }

    public function getResultTextAttr($value, $data)
    {
        if (!$data['result']) {
            return '未面试';
        }
        $result = ['未面试', '通过', '未通过', '发送Offer'];
        return $result[$data['result']];
    }

    public function getOrderTimeAttr($value)
    {
        return date('Y-m-d H:i', $value);
    }

    public function setOrderTimeAttr($value)
    {
        return strtotime($value);
    }

    public function logs()
    {
        return $this->hasMany(InterviewLog::class, 'interview_id', 'id');
    }
}
